package com.ws.shop.action.admin;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ws.shop.bean.Page;
import com.ws.shop.service.TransactionService;
import com.ws.shop.util.DateUtil;
import com.ws.shop.util.RequestUtil;

@Controller
@RequestMapping(value="/admin/transaction/*")
public class TransactionAction extends BaseAdminAction{
	private static Logger log = Logger.getLogger(TransactionAction.class);
	@Autowired
	private TransactionService transactionService;
	
	@RequestMapping(value="index.jhtml",method=RequestMethod.GET)
	public String index(HttpServletRequest request,Model model){
		String start = RequestUtil.getStringParameter(request, "start", null);
		String end = RequestUtil.getStringParameter(request, "end", null);
		String q_name = RequestUtil.getStringParameter(request, "q_name", null);
		int pageno = RequestUtil.getIntParameter(request, "pageno", 1);
		if(start == null){
			start = DateUtil.dateToString(new Date(),DateUtil.YYYY_MM_DD);
		}
		if(end == null){
			end = DateUtil.dateToString(new Date(),DateUtil.YYYY_MM_DD);
		}
		try{
			Page page = transactionService.findTransactionListPage(pageno,0,q_name,start,end);
			model.addAttribute(Page.PAGE, page);
		}catch(Exception e){
			log.error("查询交易日志失败",e);
			model.addAttribute(ERROR_MSG, "系统异常，请稍后再试");
		}
		model.addAttribute("q_name", q_name);
		model.addAttribute("start", start);
		model.addAttribute("end", end);
		return "transaction_index";
	}
	
	
}
